import { computed, reactive, ref } from 'vue'
import { defineStore } from 'pinia'
import { User } from '../api'

export const useUserStore = defineStore(
    'user',
    () => {
        // state
        // 存储用户标签
        let user_label = ref([])
        // 存储用户分组
        let user_group = ref([])
        // 存储用户等级
        let user_level = ref([])
        // getters

        // actions
        // 获取用户标签
        const init_user_label = async () => {
            let { status, msg, data } = await User.user_label_list(0)
            if (status) {
                user_label.value = data
            }
        }
        // 获取用户分组
        const init_user_group = async () => {
            let { status, msg, data } = await User.user_group_list({ page: 1, limit: 15 })
            if (status) {
                user_group.value = data
            }
        }
        // 获取用户等级
        const init_user_level = async () => {
            let { status, msg, data } = await User.vip_list()
            if (status) {
                user_level.value = data
            }
        }

        return {
            user_label,
            user_group,
            user_level,
            init_user_label,
            init_user_group,
            init_user_level,
        }
    },
    {
        // 持久化存储
        persist: {
            storage: sessionStorage, 
        }
    })